<?php
namespace app\finance\admin;
use app\system\admin\Admin;
use app\product\model\Supplier as SupplierModel;
use app\finance\model\Account as AccountModel;
use think\Db;
class Supplier extends Admin
{
	 protected $hisiModel = '';

	 public function bill()
	 {
	 	if($this->request->isAjax()){
  				$where      = $data = [];
          $page       = $this->request->param('page/d', 1);
          $limit      = $this->request->param('limit/d', 15);
          $bill_id    = $this->request->param('bill_id','');
					$type       = $this->request->param('type',1);
          if ($bill_id) {
              $where['supplier_id'] = $bill_id;
          }
          $where['out_in'] = 2;
			if($type == 2){
				$data['data']   = Db::name('supplier_money')->alias('sm')
								->join('hisi_supplier s','s.id=sm.supplier_id')
								->join('hisi_account a','a.id=sm.account_id')
								->field('sm.*,s.name as supplier_name, a.name as account_name')
								->where($where)->order('id desc')
								// ->page($page)->limit($limit)
								->select();
				$data['count']  = Db::name('supplier_money')->where($where)->count('id');
				$data['code']   = 0;
				return json($data);
			}else{
				$data['data']   = Db::name('supplier_money')->alias('sm')
					            ->join('hisi_supplier s','s.id=sm.supplier_id')
					            ->join('hisi_account a','a.id=sm.account_id')
					            ->field('sm.*,s.name as supplier_name, a.name as account_name')
					            ->where($where)->order('id desc')
					            ->page($page)->limit($limit)->select();
	            $data['count']  = Db::name('supplier_money')->where($where)->count('id');
	            $data['code']   = 0;
	            return json($data);
			}

    	}
		$bills = Db::name('supplier')->field('id,name')->all();
		$this->assign('bills',$bills);
    	return $this->fetch();
	 }

}
